package com.kucai.yifaqapp.presenter.activity;

import android.widget.Toast;

import com.kucai.yifaqapp.global.HttpAdress;
import com.kucai.yifaqapp.model.CustomObserver;
import com.kucai.yifaqapp.model.network.HttpJsonUtils;
import com.kucai.yifaqapp.model.network.entity.res.ResGuanfang;
import com.kucai.yifaqapp.model.network.entity.res.ResGuanfang2;
import com.kucai.yifaqapp.model.network.entity.res.Resdraw;
import com.kucai.yifaqapp.ui.activity.ActivityDetails;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/12/8.
 */

public class ActivityDetailsPresenter extends BaseActivityPresenter<ActivityDetails> {
    public ActivityDetailsPresenter(ActivityDetails mActivity) {
        super(mActivity);
    }

    //官方
    public void getguanfangactivitys(String id, String imgid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getguanfangactivitys(HttpAdress.getuseAdress() + "api/m/activity/detail",id, imgid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResGuanfang>(mActivity) {

                    @Override
                    protected void onCustomNext(ResGuanfang resActivitys) {
                        if (resActivitys.data != null && resActivitys.data.content != null) {
                            mActivity.getguanfang(resActivitys);
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
//                        Toast.makeText(mFragment.getContext(), "开元游戏，获取失败", Toast.LENGTH_LONG).show();
                    }
                });
    }

    //官方
    public void getguanfangactivitys2(String id, String imgid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getguanfangactivitys2(HttpAdress.getuseAdress() + "api/m/activity/detail",id, imgid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResGuanfang2>(mActivity) {

                    @Override
                    protected void onCustomNext(ResGuanfang2 resActivitys) {
                        if (resActivitys.data != null && resActivitys.data.content != null) {
                            mActivity.getguanfang2(resActivitys);
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
//                        Toast.makeText(mFragment.getContext(), "开元游戏，获取失败", Toast.LENGTH_LONG).show();
                    }
                });
    }

    //抽奖
    public void getdraw(String id, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getdraw(HttpAdress.getuseAdress() + "api/m/activity/draw",id, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resdraw>(mActivity) {
                    @Override
                    protected void onCustomNext(Resdraw resdraw) {
                        if (resdraw.code.equals("0")) {
                            mActivity.getdraw(resdraw);
                        } else {
                            Toast.makeText(mActivity, resdraw.msg, Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
//                        Toast.makeText(mFragment.getContext(), "开元游戏，获取失败", Toast.LENGTH_LONG).show();
                    }
                });
    }

}